package com.loongtech.bi.manager.report;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.bi.action.UIHelper;
import com.loongtech.bi.entity.pay.*;
import com.loongtech.bi.entity.player.*;
import com.loongtech.bi.manager.pay.NotIdfaFirstPayUserManager;
import com.loongtech.bi.manager.pay.NotIdfaNewUserLTVManager;
import com.loongtech.bi.manager.pay.NotIdfaPayUserManager;
import com.loongtech.bi.manager.pay.NotIdfaTotalCashManager;
import com.loongtech.bi.manager.player.*;
import com.loongtech.bi.manager.system.BiPlatformManager;
import com.loongtech.bi.support.Helper;
import com.loongtech.bi.support.chart.ChartData1;
import com.loongtech.bi.support.chart.ChartFlow;
import com.loongtech.bi.support.chart.ChartSelect;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.Map.Entry;

/**
 * 运营报表-IOS正版（去积分墙）Action
 * 
 * @author marin
 * @date 2015-09-15
 */
@Service
public class NotIdfaReportManager extends ManagerQueryCacheBase<Object> {
	private static final long serialVersionUID = 1L;

	@Autowired
	NotIdfaNewUserManager notIdfaNewUserManager;
	@Autowired
	NotIdfaLeftManager notIdfaLeftManager;
	@Autowired
    NotIdfaSevenLoginPercentManager notIdfaSevenLoginPercentManager;
	@Autowired
    NotIdfaDauManager notIdfaDauManager;
	@Autowired
    NotIdfaDaPlayTimeManager notIdfaDaPlayTimeManager;
	@Autowired
    NotIdfaTotalCashManager notIdfaTotalCashManager;
	@Autowired
    NotIdfaFirstPayUserManager notIdfaFirstPayUserManager;
	@Autowired
    NotIdfaPayUserManager notIdfaPayUserManager;
	@Autowired
    NotIdfaNewUserLTVManager notIdfaNewUserLTVManager;

	/**
	 * 得到符合条件的所有数据
	 *
	 * @return
	 */
	public List<NotIdfaReportData> getAllGameReportData(Date dateStart, Date dateEnd) {
		Map<String, NotIdfaReportData> tmpGRMap = new LinkedHashMap<>(); // key=day+platform+channel+server

		// 新增帐号
		List<EntityNotIdfaNewUser> list = notIdfaNewUserManager.getNewUsersByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list)) {
			for (EntityNotIdfaNewUser o : list) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setNewUser(o.getNew_user());
				
				int d = Time.getInterval(o.getDay(), new Date()) + 1;
				tmp.setTheLtvNewUser(d, o.getNew_user());
			}
		} else {
			//return null;
		}

		// 留存
		List<EntityNotIdfaSecondLeft> list1 = notIdfaLeftManager.getLeftByDate(dateStart, dateEnd, EntityNotIdfaSecondLeft.class);
		if (!Helper.isEmptyValue(list1)) {
			for (EntityNotIdfaSecondLeft o : list1) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setThe2Left(o.getUser_second_left());
				tmp.setThe2LeftLoginusernum(o.getLoginusernum());
				tmp.setThe2LeftUsercreatenum(o.getUsercreatenum());
			}
		}
		List<EntityNotIdfaThirdLeft> list2 = notIdfaLeftManager.getLeftByDate(dateStart, dateEnd, EntityNotIdfaThirdLeft.class);
		if (!Helper.isEmptyValue(list2)) {
			for (EntityNotIdfaThirdLeft o : list2) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setThe3Left(o.getUser_third_left());
				tmp.setThe3LeftLoginusernum(o.getLoginusernum());
				tmp.setThe3LeftUsercreatenum(o.getUsercreatenum());
			}
		}
		List<EntityNotIdfaSevenLeft> list3 = notIdfaLeftManager.getLeftByDate(dateStart, dateEnd, EntityNotIdfaSevenLeft.class);
		if (!Helper.isEmptyValue(list3)) {
			for (EntityNotIdfaSevenLeft o : list3) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setThe7Left(o.getUser_seven_left());
				tmp.setThe7LeftLoginusernum(o.getLoginusernum());
				tmp.setThe7LeftUsercreatenum(o.getUsercreatenum());
			}
		}
		List<EntityNotIdfaFourteenLeft> list4 = notIdfaLeftManager.getLeftByDate(dateStart, dateEnd, EntityNotIdfaFourteenLeft.class);
		if (!Helper.isEmptyValue(list4)) {
			for (EntityNotIdfaFourteenLeft o : list4) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setThe14Left(o.getUser_fourteen_left());
				tmp.setThe14LeftLoginusernum(o.getLoginusernum());
				tmp.setThe14LeftUsercreatenum(o.getUsercreatenum());
			}
		}
		List<EntityNotIdfaMonthLeft> list5 = notIdfaLeftManager.getLeftByDate(dateStart, dateEnd, EntityNotIdfaMonthLeft.class);
		if (!Helper.isEmptyValue(list5)) {
			for (EntityNotIdfaMonthLeft o : list5) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setThe30Left(o.getUser_month_left());
				tmp.setThe30LeftLoginusernum(o.getLoginusernum());
				tmp.setThe30LeftUsercreatenum(o.getUsercreatenum());
			}
		}

		// 有效新增用户数
		List<EntityNotIdfaSevenLoginPercent> list6 = notIdfaSevenLoginPercentManager.getSevenLoginPercentByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list6)) {
			for (EntityNotIdfaSevenLoginPercent o : list6) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setValidatedNewUser(o.getTwo_login_times());

				// 登录比新增用户有效率
				tmp.setLoginNewUservalidatedRadio((float) (tmp.getValidatedNewUser() * 1.0 / (tmp.getNewUser() == 0 ? 1 : tmp.getNewUser())));

				// 登录比留存用户数
				tmp.setLoginRadioAliveUserCount(o.getThree_login_times());

				// 登录比
				tmp.setLoginRadio((float) (tmp.getLoginRadioAliveUserCount() * 1.0 / (tmp.getValidatedNewUser() == 0 ? 1 : tmp.getValidatedNewUser())));
			}
		}

		// 分日活跃帐号数
		List<EntityNotIdfaDau> list7 = notIdfaDauManager.getDauByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list7)) {
			for (EntityNotIdfaDau o : list7) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(o.getStartday());
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setActiveUserCountByDay(o.getDau());
			}
		}
		
		// 活跃帐号总数
		List<EntityNotIdfaDau> list71 = notIdfaDauManager.getAllDauByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list71)) {
			for (EntityNotIdfaDau o : list71) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(o.getStartday());
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setActiveUserCount(o.getDau());
			}
		}

		// 人均在线时长(m)
		List<EntityNotIdfaDaPlayTime> list8 = notIdfaDaPlayTimeManager.getDaPlayTimeByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list8)) {
			for (EntityNotIdfaDaPlayTime o : list8) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setSumplaytime(o.getSumplaytime());
				tmp.setUseridnum(o.getUseridnum());
				tmp.setAvgOnlineTime((int)o.getDa_playtime());
			}
		}

		// 付费金额
		List<EntityNotIdfaTotalCash> list9 = notIdfaTotalCashManager.getTotalCashByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list9)) {
			for (EntityNotIdfaTotalCash o : list9) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}
				tmp.setPayCount(UIHelper.getYuan(o.getTotal_cash()));
			}
		}

		// 分日付费帐号数
		List<EntityNotIdfaPayUser> list10 = notIdfaPayUserManager.getPayUserByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list10)) {
			for (EntityNotIdfaPayUser o : list10) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(o.getStartday());
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setPayUserCountByDay(o.getAddcash_user());
				// 活跃付费率
				tmp.setActivePayRadio((float) ((tmp.getPayUserCountByDay()) * 1.0 / (tmp.getActiveUserCountByDay() == 0 ? 1 : tmp.getActiveUserCountByDay())));

				// 付费ARPU
				tmp.setPayARPU(tmp.getPayUserCountByDay() == 0 ? 0 : PageHelper.floatKeepTwoNumber(tmp.getPayCount() * 1.0 / tmp.getPayUserCountByDay()));

				// 活跃ARPU
				tmp.setActiveARPU(tmp.getActiveUserCountByDay() == 0 ? 0 : PageHelper.floatKeepTwoNumber(tmp.getPayCount() * 1.0 / tmp.getActiveUserCountByDay()));
			}
		}
		
		// 付费账号总数
		List<EntityNotIdfaPayUser> list12 = notIdfaPayUserManager.getAllPayUserByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list12)) {
			for (EntityNotIdfaPayUser o : list12) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(o.getStartday());
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setPayUserCount(o.getAddcash_user());
			}
		}

		// 首次付费账号数
		List<EntityNotIdfaFirstPayUser> list11 = notIdfaFirstPayUserManager.getFirstPayUserByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list11)) {
			for (EntityNotIdfaFirstPayUser o : list11) {
				String key = o.getKey();
                NotIdfaReportData tmp = tmpGRMap.get(key);
				if (tmp == null) {
					tmp = new NotIdfaReportData();
					tmp.setDateStr(Time.getDateStr(o.getDay()));
					tmp.setPlatformId(o.getPlatformid());
					tmp.setChannelId(o.getChannelid());
					tmp.setServerId(o.getServerid());
					tmpGRMap.put(key, tmp);
				}

				tmp.setFirstPayUserCount(o.getFirstpayuser());
			}
		}

		// LTV
		List<EntityNotIdfaNewUserLTV> list13 = notIdfaNewUserLTVManager.getAllNewUserLTVByDate(dateStart, dateEnd);
		if (!Helper.isEmptyValue(list13)) {
			for (EntityNotIdfaNewUserLTV o : list13) {
				int d = Time.getInterval(Time.formatDate(o.getStartday(), "yyyy-MM-dd"), Time.formatDate(o.getEndday(), "yyyy-MM-dd")) + 1;  // 充值日与创建日相差天数
				if (d == 7 || d == 14 || d == 30) {
					String key = o.getKey();
                    NotIdfaReportData tmp = tmpGRMap.get(key);
					if (tmp == null) {
						tmp = new NotIdfaReportData();
						tmp.setDateStr(o.getStartday());
						tmp.setPlatformId(o.getPlatformid());
						tmp.setChannelId(o.getChannelid());
						tmp.setServerId(o.getServerid());
						tmpGRMap.put(key, tmp);
					}

					tmp.setThePayUser(d, UIHelper.getYuan(o.getCashadd()));
					tmp.setTheLTV(d, UIHelper.getYuan(o.getCashadd()));
				}
			}
		}
		
		// 新增账号付费人数 TODO
		// 新增账号付费金额 TODO
		// 新增账号付费率 TODO

		return new ArrayList<>(tmpGRMap.values());
	}

    public void updateData(List<NotIdfaReportData> allData, List<NotIdfaReportData> platformDataList) {
        Map<String, List<NotIdfaReportData>> paltformDataMap = new HashMap<>(); // 平台辅助map

        Set<String> dateSet = new HashSet<>();  // 日期串set
        for (NotIdfaReportData oa : allData) {
            dateSet.add(oa.getDateStr());

            if (oa.isAllData() || !"0".equals(oa.getPlatformId())) {  // 全平台或者平台id不为0的，即按平台统计的
                List<NotIdfaReportData> oal1 = paltformDataMap.get(oa.getPlatformId());
                if (oal1 == null) {
                    oal1 = new ArrayList<>();
                    paltformDataMap.put(oa.getPlatformId(), oal1);
                }
                oal1.add(oa);
            }
        }

        // 组装平台数据
        for (Entry<String, List<NotIdfaReportData>> entry : paltformDataMap.entrySet()) {
            List<NotIdfaReportData> value = entry.getValue();
            Collections.sort(value, new NotIdfaReportData().comparatorDate);
            NotIdfaReportData oa = new NotIdfaReportData();
            oa.setTogglerDatas(value);
            oa.setPlatformId(entry.getKey());
            for (NotIdfaReportData o : value) {
                oa.setNewDevice(oa.getNewDevice() + o.getNewDevice());
                oa.setNewUser(oa.getNewUser() + o.getNewUser());
                oa.setThe2LeftLoginusernum(oa.getThe2LeftLoginusernum() + o.getThe2LeftLoginusernum());
                oa.setThe2LeftUsercreatenum(oa.getThe2LeftUsercreatenum() + o.getThe2LeftUsercreatenum());
                oa.setThe3LeftLoginusernum(oa.getThe3LeftLoginusernum() + o.getThe3LeftLoginusernum());
                oa.setThe3LeftUsercreatenum(oa.getThe3LeftUsercreatenum() + o.getThe3LeftUsercreatenum());
                oa.setThe7LeftLoginusernum(oa.getThe7LeftLoginusernum() + o.getThe7LeftLoginusernum());
                oa.setThe7LeftUsercreatenum(oa.getThe7LeftUsercreatenum() + o.getThe7LeftUsercreatenum());
                oa.setThe14LeftLoginusernum(oa.getThe14LeftLoginusernum() + o.getThe14LeftLoginusernum());
                oa.setThe14LeftUsercreatenum(oa.getThe14LeftUsercreatenum() + o.getThe14LeftUsercreatenum());
                oa.setThe30LeftLoginusernum(oa.getThe30LeftLoginusernum() + o.getThe30LeftLoginusernum());
                oa.setThe30LeftUsercreatenum(oa.getThe30LeftUsercreatenum() + o.getThe30LeftUsercreatenum());
                oa.setValidatedNewUser(oa.getValidatedNewUser() + o.getValidatedNewUser());
                oa.setLoginRadioAliveUserCount(oa.getLoginRadioAliveUserCount() + o.getLoginRadioAliveUserCount());
                oa.setActiveUserCount(oa.getActiveUserCount() + o.getActiveUserCount());
                oa.setSumplaytime(oa.getSumplaytime() + o.getSumplaytime());
                oa.setUseridnum(oa.getUseridnum() + o.getUseridnum());
                oa.setAvgOnlineTime(oa.getAvgOnlineTime() + o.getAvgOnlineTime());
                oa.setPayCount(oa.getPayCount() + o.getPayCount());
                oa.setPayUserCount(oa.getPayUserCount() + o.getPayUserCount());
                oa.setFirstPayUserCount(oa.getFirstPayUserCount() + o.getFirstPayUserCount());
                oa.setNewPayUserCount(oa.getNewPayUserCount() + o.getNewPayUserCount());
                oa.setNewUserPayCount(oa.getNewUserPayCount() + o.getNewUserPayCount());
                oa.setThe7ltvNewUser(oa.getThe7ltvNewUser() + o.getThe7ltvNewUser());
                oa.setThe14ltvNewUser(oa.getThe14ltvNewUser() + o.getThe14ltvNewUser());
                oa.setThe30ltvNewUser(oa.getThe30ltvNewUser() + o.getThe30ltvNewUser());
                oa.setThePayUser(7, oa.getThe7PayUser() + o.getThe7PayUser());
                oa.setThePayUser(14, oa.getThe14PayUser() + o.getThe14PayUser());
                oa.setThePayUser(30, oa.getThe30PayUser() + o.getThe30PayUser());
            }
            platformDataList.add(oa);
        }
        for (NotIdfaReportData tt : platformDataList) {
            tt.setThe2Left((float) (tt.getThe2LeftLoginusernum() * 1.0 / (tt.getThe2LeftUsercreatenum() == 0 ? 1 : tt.getThe2LeftUsercreatenum())));
            tt.setThe3Left((float) (tt.getThe3LeftLoginusernum() * 1.0 / (tt.getThe3LeftUsercreatenum() == 0 ? 1 : tt.getThe3LeftUsercreatenum())));
            tt.setThe7Left((float) (tt.getThe7LeftLoginusernum() * 1.0 / (tt.getThe7LeftUsercreatenum() == 0 ? 1 : tt.getThe7LeftUsercreatenum())));
            tt.setThe14Left((float) (tt.getThe14LeftLoginusernum() * 1.0 / (tt.getThe14LeftUsercreatenum() == 0 ? 1 : tt.getThe14LeftUsercreatenum())));
            tt.setThe30Left((float) (tt.getThe30LeftLoginusernum() * 1.0 / (tt.getThe30LeftUsercreatenum() == 0 ? 1 : tt.getThe30LeftUsercreatenum())));
            tt.setLoginNewUservalidatedRadio((float) (tt.getValidatedNewUser() * 1.0 / (tt.getNewUser() == 0 ? 1 : tt.getNewUser())));
            tt.setLoginRadio((float) (tt.getLoginRadioAliveUserCount() * 1.0 / (tt.getValidatedNewUser() == 0 ? 1 : tt.getValidatedNewUser())));
            tt.setAvgOnlineTime((int)(tt.getAvgOnlineTime() * 1.0 / 60));
            tt.setActivePayRadio((float) ((tt.getPayUserCount()) * 1.0 / (tt.getActiveUserCount() == 0 ? 1 : tt.getActiveUserCount())));
            tt.setPayCount(tt.getPayCount());
            tt.setPayARPU(tt.getPayUserCount() == 0 ? 0 : PageHelper.floatKeepTwoNumber(tt.getPayCount() * 1.0 / tt.getPayUserCount()));
            tt.setActiveARPU(tt.getActiveUserCount() == 0 ? 0 : PageHelper.floatKeepTwoNumber(tt.getPayCount() * 1.0 / tt.getActiveUserCount()));

            tt.setTheLTV(7, tt.getThe7PayUser());
            tt.setTheLTV(14, tt.getThe14PayUser());
            tt.setTheLTV(30, tt.getThe30PayUser());
            tt.setNewUserPayRatio((float) (0.0)); // TODO
            tt.setNewPayUserARPU(0); // TODO
        }
        Collections.sort(platformDataList, new NotIdfaReportData().comparatorPlatformId);
    }


	// 前端数据类，饼状图数据类
	public class NotIdfaReportData {
		private String platformId;
		private String channelId;
		private String serverId;
		@ChartFlow(name = "渠道")
		private String channelName;
		private String dateStr; // 日期

		private int newDevice; // 新增设备数
		@ChartSelect(name = "新增帐号", key = 1)
		@ChartData1(name = "新增帐号", key = 1)
		private int newUser; // 新增帐号数
		private int the7ltvNewUser;  // 7日ltv新增帐号数
		private int the14ltvNewUser;  // 14日ltv新增帐号数
		private int the30ltvNewUser;  // 30日ltv新增帐号数
		private float the2Left; // 新增帐号次日留存率
		private int the2LeftLoginusernum; // 次日登录数，次日留存的分子
		private int the2LeftUsercreatenum; // 次日创建数，次日留存的分母
		private float the3Left; // 新增帐号3日留存率
		private int the3LeftLoginusernum; // 次日登录数，3日留存的分子
		private int the3LeftUsercreatenum; // 次日创建数，3日留存的分母
		private float the7Left; // 新增帐号7日留存率
		private int the7LeftLoginusernum; // 次日登录数，7日留存的分子
		private int the7LeftUsercreatenum; // 次日创建数，7日留存的分母
		private float the14Left; // 新增帐号14日留存率
		private int the14LeftLoginusernum; // 次日登录数，14日留存的分子
		private int the14LeftUsercreatenum; // 次日创建数，14日留存的分母
		private float the30Left; // 新增帐号30日留存率
		private int the30LeftLoginusernum; // 次日登录数，30日留存的分子
		private int the30LeftUsercreatenum; // 次日创建数，30日留存的分母
		private int validatedNewUser; // 有效新增用户数
		private float loginNewUservalidatedRadio; // 登录比新增用户有效率
		private int loginRadioAliveUserCount; // 登录比留存用户数
		private float loginRadio; // 登录比
		@ChartSelect(name = "活跃帐号", key = 2)
		@ChartData1(name = "活跃帐号", key = 2)
		private int activeUserCount; // 活跃账号总数
		private int activeUserCountByDay;  // 单日活跃帐号数
		private int avgOnlineTime; // 人均在线时长(m)
		private long sumplaytime; // 在线总时长
		private long useridnum; // 在线总人数
		@ChartSelect(name = "付费金额", key = 3)
		@ChartData1(name = "付费金额", key = 3)
		private int payCount; // 付费金额
		private int payUserCount; // 付费账号数
		private int payUserCountByDay; // 单日付费账号数
		private int firstPayUserCount; // 首次付费账号数
		private float activePayRadio; // 活跃付费率
		private float payARPU; // 付费ARPU
		private float activeARPU; // 活跃ARPU
		private int newPayUserCount; // 新增账号付费人数
		private int newUserPayCount; // 新增账号付费金额
		private float newUserPayRatio; // 新增账号付费率
		private float newPayUserARPU; // 新增账号付费ARPU
		private int the7PayUser;  // 7日付费
		private int the14PayUser;  // 14日付费
		private int the30PayUser;  // 30日付费
		private float the7LTV; // 7日LTV
		private float the14LTV; // 14日LTV
		private float the30LTV; // 30日LTV

		private List<NotIdfaReportData> togglerDatas; // 点击扩展显示的数据
		
		// 根据日期排序的比较器
		public final Comparator<NotIdfaReportData> comparatorDate = new Comparator<NotIdfaReportData>() {
			public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
				return s2.getDateStr().compareTo(s1.getDateStr()); //(int) (Time.formatDateStr(s2.getDateStr(), "yyyy-MM-dd") - Time.formatDateStr(s1.getDateStr(), "yyyy-MM-dd"));
			}
		};
		
		// 根据serverid排序的比较器
		public final Comparator<NotIdfaReportData> comparatorServer = new Comparator<NotIdfaReportData>() {
			public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
				return s1.getServerId().compareTo(s2.getServerId());
			}
		};

        public final Comparator<NotIdfaReportData> comparatorPlatformId = new Comparator<NotIdfaReportData>() {
            public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
                if ("0".equals(s1.getPlatformId())) {
                    return 1;
                } else {
                    return -1;
                }
            }
        };

		public final Comparator<NotIdfaReportData> comparatorPlatformName = new Comparator<NotIdfaReportData>() {
			public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
				return BiPlatformManager.getPlatformNameById(s1.getPlatformId()).compareTo(BiPlatformManager.getPlatformNameById(s2.getPlatformId()));
			}
		};
		
		public final Comparator<NotIdfaReportData> comparatorChannelName = new Comparator<NotIdfaReportData>() {
			public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
				return BiPlatformManager.getChannelNameById(s1.getChannelId()).compareTo(BiPlatformManager.getChannelNameById(s2.getChannelId()));
			}
		};
		
		public final Comparator<NotIdfaReportData> comparatorServerName = new Comparator<NotIdfaReportData>() {
			public int compare(NotIdfaReportData s1, NotIdfaReportData s2) {
				return BiPlatformManager.getServerNameById(s1.getServerId()).compareTo(BiPlatformManager.getServerNameById(s2.getServerId()));
			}
		};
		
		// 是不是总体数据（）
		public boolean isAllData() {
			return "0".equals(platformId) && "0".equals(channelId) && "0".equals(serverId);
		}

		public void setTheLtvNewUser(int d, int newUser) {
			if (d >= 7) {
				the7ltvNewUser = newUser;
			}
			if (d >= 14 ) {
				the14ltvNewUser = newUser;
			}
			if (d >= 30) {
				the30ltvNewUser = newUser;
			}
		}
		
		public void setThePayUser(int d, int payUser) {
			if (d == 7) {
				the7PayUser = payUser;
			} else if (d == 14) {
				the14PayUser = payUser;
			} else if (d == 30) {
				the30PayUser = payUser;
			}
		}
		
		public void setTheLTV(int d, int cashadd) {
			if (d == 7) {
				the7LTV = PageHelper.floatKeepTwoNumber(the7ltvNewUser == 0 ? 0 : (float)(cashadd * 1.0 / the7ltvNewUser));
			} else if (d == 14) {
				the14LTV = PageHelper.floatKeepTwoNumber(the14ltvNewUser == 0 ? 0 : (float)(cashadd * 1.0 / the14ltvNewUser));
			} else if (d == 30) {
				the30LTV = PageHelper.floatKeepTwoNumber(the30ltvNewUser == 0 ? 0 : (float)(cashadd * 1.0 / the30ltvNewUser));
			}
		}
		
		public String getPlatformId() {
			return platformId;
		}

		public void setPlatformId(String platformId) {
			this.platformId = platformId;
		}

		public String getChannelId() {
			return channelId;
		}

		public void setChannelId(String channelId) {
			this.channelId = channelId;
			this.channelName = BiPlatformManager.getChannelNameById(channelId);
		}

		public String getServerId() {
			return serverId;
		}

		public void setServerId(String serverId) {
			this.serverId = serverId;
		}

		public String getChannelName() {
			return channelName;
		}

		public void setChannelName(String channelName) {
			this.channelName = channelName;
		}

		public String getDateStr() {
			return dateStr;
		}

		public void setDateStr(String dateStr) {
			this.dateStr = dateStr;
		}

		public int getNewDevice() {
			return newDevice;
		}

		public void setNewDevice(int newDevice) {
			this.newDevice = newDevice;
		}

		public int getNewUser() {
			return newUser;
		}

		public void setNewUser(int newUser) {
			this.newUser = newUser;
		}

		public float getThe2Left() {
			return the2Left;
		}

		public void setThe2Left(float the2Left) {
			this.the2Left = the2Left;
		}

		public float getThe3Left() {
			return the3Left;
		}

		public void setThe3Left(float the3Left) {
			this.the3Left = the3Left;
		}

		public float getThe7Left() {
			return the7Left;
		}

		public void setThe7Left(float the7Left) {
			this.the7Left = the7Left;
		}

		public float getThe14Left() {
			return the14Left;
		}

		public void setThe14Left(float the14Left) {
			this.the14Left = the14Left;
		}

		public float getThe30Left() {
			return the30Left;
		}

		public void setThe30Left(float the30Left) {
			this.the30Left = the30Left;
		}

		public int getValidatedNewUser() {
			return validatedNewUser;
		}

		public void setValidatedNewUser(int validatedNewUser) {
			this.validatedNewUser = validatedNewUser;
		}

		public float getLoginNewUservalidatedRadio() {
			return loginNewUservalidatedRadio;
		}

		public void setLoginNewUservalidatedRadio(float loginNewUservalidatedRadio) {
			this.loginNewUservalidatedRadio = loginNewUservalidatedRadio;
		}

		public int getLoginRadioAliveUserCount() {
			return loginRadioAliveUserCount;
		}

		public void setLoginRadioAliveUserCount(int loginRadioAliveUserCount) {
			this.loginRadioAliveUserCount = loginRadioAliveUserCount;
		}

		public float getLoginRadio() {
			return loginRadio;
		}

		public void setLoginRadio(float loginRadio) {
			this.loginRadio = loginRadio;
		}

		public int getActiveUserCount() {
			return activeUserCount;
		}

		public void setActiveUserCount(int activeUserCount) {
			this.activeUserCount = activeUserCount;
		}

		public int getAvgOnlineTime() {
			return avgOnlineTime;
		}

		public void setAvgOnlineTime(int avgOnlineTime) {
			this.avgOnlineTime = avgOnlineTime;
		}

		public int getPayCount() {
			return payCount;
		}

		public void setPayCount(int payCount) {
			this.payCount = payCount;
		}

		public int getPayUserCount() {
			return payUserCount;
		}

		public void setPayUserCount(int payUserCount) {
			this.payUserCount = payUserCount;
		}

		public int getFirstPayUserCount() {
			return firstPayUserCount;
		}

		public void setFirstPayUserCount(int firstPayUserCount) {
			this.firstPayUserCount = firstPayUserCount;
		}

		public float getActivePayRadio() {
			return activePayRadio;
		}

		public void setActivePayRadio(float activePayRadio) {
			this.activePayRadio = activePayRadio;
		}

		public float getPayARPU() {
			return payARPU;
		}

		public void setPayARPU(float payARPU) {
			this.payARPU = payARPU;
		}

		public float getActiveARPU() {
			return activeARPU;
		}

		public void setActiveARPU(float activeARPU) {
			this.activeARPU = activeARPU;
		}

		public int getNewPayUserCount() {
			return newPayUserCount;
		}

		public void setNewPayUserCount(int newPayUserCount) {
			this.newPayUserCount = newPayUserCount;
		}

		public int getNewUserPayCount() {
			return newUserPayCount;
		}

		public void setNewUserPayCount(int newUserPayCount) {
			this.newUserPayCount = newUserPayCount;
		}

		public float getNewUserPayRatio() {
			return newUserPayRatio;
		}

		public void setNewUserPayRatio(float newUserPayRatio) {
			this.newUserPayRatio = newUserPayRatio;
		}

		public float getNewPayUserARPU() {
			return newPayUserARPU;
		}

		public void setNewPayUserARPU(float newPayUserARPU) {
			this.newPayUserARPU = newPayUserARPU;
		}

		public float getThe7LTV() {
			return the7LTV;
		}

		public void setThe7LTV(float the7ltv) {
			the7LTV = the7ltv;
		}

		public float getThe14LTV() {
			return the14LTV;
		}

		public void setThe14LTV(float the14ltv) {
			the14LTV = the14ltv;
		}

		public float getThe30LTV() {
			return the30LTV;
		}

		public void setThe30LTV(float the30ltv) {
			the30LTV = the30ltv;
		}

		public int getThe2LeftLoginusernum() {
			return the2LeftLoginusernum;
		}

		public void setThe2LeftLoginusernum(int the2LeftLoginusernum) {
			this.the2LeftLoginusernum = the2LeftLoginusernum;
		}

		public int getThe2LeftUsercreatenum() {
			return the2LeftUsercreatenum;
		}

		public void setThe2LeftUsercreatenum(int the2LeftUsercreatenum) {
			this.the2LeftUsercreatenum = the2LeftUsercreatenum;
		}

		public int getThe3LeftLoginusernum() {
			return the3LeftLoginusernum;
		}

		public void setThe3LeftLoginusernum(int the3LeftLoginusernum) {
			this.the3LeftLoginusernum = the3LeftLoginusernum;
		}

		public int getThe3LeftUsercreatenum() {
			return the3LeftUsercreatenum;
		}

		public void setThe3LeftUsercreatenum(int the3LeftUsercreatenum) {
			this.the3LeftUsercreatenum = the3LeftUsercreatenum;
		}

		public int getThe7LeftLoginusernum() {
			return the7LeftLoginusernum;
		}

		public void setThe7LeftLoginusernum(int the7LeftLoginusernum) {
			this.the7LeftLoginusernum = the7LeftLoginusernum;
		}

		public int getThe7LeftUsercreatenum() {
			return the7LeftUsercreatenum;
		}

		public void setThe7LeftUsercreatenum(int the7LeftUsercreatenum) {
			this.the7LeftUsercreatenum = the7LeftUsercreatenum;
		}

		public int getThe14LeftLoginusernum() {
			return the14LeftLoginusernum;
		}

		public void setThe14LeftLoginusernum(int the14LeftLoginusernum) {
			this.the14LeftLoginusernum = the14LeftLoginusernum;
		}

		public int getThe14LeftUsercreatenum() {
			return the14LeftUsercreatenum;
		}

		public void setThe14LeftUsercreatenum(int the14LeftUsercreatenum) {
			this.the14LeftUsercreatenum = the14LeftUsercreatenum;
		}

		public int getThe30LeftLoginusernum() {
			return the30LeftLoginusernum;
		}

		public void setThe30LeftLoginusernum(int the30LeftLoginusernum) {
			this.the30LeftLoginusernum = the30LeftLoginusernum;
		}

		public int getThe30LeftUsercreatenum() {
			return the30LeftUsercreatenum;
		}

		public void setThe30LeftUsercreatenum(int the30LeftUsercreatenum) {
			this.the30LeftUsercreatenum = the30LeftUsercreatenum;
		}

		public long getSumplaytime() {
			return sumplaytime;
		}

		public void setSumplaytime(long sumplaytime) {
			this.sumplaytime = sumplaytime;
		}

		public long getUseridnum() {
			return useridnum;
		}

		public void setUseridnum(long useridnum) {
			this.useridnum = useridnum;
		}

		public List<NotIdfaReportData> getTogglerDatas() {
			return togglerDatas;
		}

		public void setTogglerDatas(List<NotIdfaReportData> togglerDatas) {
			this.togglerDatas = togglerDatas;
		}

		public int getActiveUserCountByDay() {
			return activeUserCountByDay;
		}

		public void setActiveUserCountByDay(int activeUserCountByDay) {
			this.activeUserCountByDay = activeUserCountByDay;
		}

		public int getPayUserCountByDay() {
			return payUserCountByDay;
		}

		public void setPayUserCountByDay(int payUserCountByDay) {
			this.payUserCountByDay = payUserCountByDay;
		}

		public int getThe7PayUser() {
			return the7PayUser;
		}

		public void setThe7PayUser(int the7PayUser) {
			this.the7PayUser = the7PayUser;
		}

		public int getThe14PayUser() {
			return the14PayUser;
		}

		public void setThe14PayUser(int the14PayUser) {
			this.the14PayUser = the14PayUser;
		}

		public int getThe30PayUser() {
			return the30PayUser;
		}

		public void setThe30PayUser(int the30PayUser) {
			this.the30PayUser = the30PayUser;
		}

		public int getThe7ltvNewUser() {
			return the7ltvNewUser;
		}

		public void setThe7ltvNewUser(int the7ltvNewUser) {
			this.the7ltvNewUser = the7ltvNewUser;
		}

		public int getThe14ltvNewUser() {
			return the14ltvNewUser;
		}

		public void setThe14ltvNewUser(int the14ltvNewUser) {
			this.the14ltvNewUser = the14ltvNewUser;
		}

		public int getThe30ltvNewUser() {
			return the30ltvNewUser;
		}

		public void setThe30ltvNewUser(int the30ltvNewUser) {
			this.the30ltvNewUser = the30ltvNewUser;
		}
	}
}
